package service

import (
	"encoding/json"
	"fmt"
	"usplatformserver/pkg/zmq"
)

type AiRecommendRequest struct {
	OrganType    *int   `json:"organType" form:"organType" binding:"required,gte=0"`
	PatientStamp string `json:"patientStamp" form:"patientStamp"`
}

// 获取ai推荐结果请求
type msgGetAiRecommendRetReq struct {
	MsgType uint32 `json:"msgType"`
	*AiRecommendRequest
}

// 获取Ai推荐结果
func (svc *Service) GetAiRecommendTubercles(addr string, param *AiRecommendRequest) ([]*int, error) {
	//组zmq消息
	fmt.Println(param)
	var msgReq msgGetAiRecommendRetReq
	msgReq.AiRecommendRequest = param
	msgReq.MsgType = zmq.MsgGetAiRecommendTubercles.MsgType

	msgReqStr, err := json.Marshal(msgReq)
	if err != nil {
		fmt.Println("json.Marshal(msgGetAiRecommendRetReq) failed: ", err)
		return nil, err
	}

	rcvMsg, err := zmq.SendMessage(addr, string(msgReqStr))
	fmt.Println(rcvMsg)
	var rcv []*int
	err = json.Unmarshal([]byte(rcvMsg), &rcv)
	if err != nil {
		fmt.Println("json.Unmarshal(recommend tubercle ids) failed: ", err)
		return nil, err
	}

	return rcv, nil
}
